<template>
	<view class="success-dialog-cover">
		<view class="success-dialog">
			<view class="dialog-content">
				<slot></slot>
			</view>
			<view class="dialog-footer">
				<view @click="handleCallback(false)" v-if="showCancel" class="dialog-btn cancel-btn">{{cancelText}}
				</view>
				<view v-if="showCancel" class="line"></view>
				<view @click="handleCallback(true)" class="dialog-btn confirm-btn">{{confirmText}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'SuccessDialog',
		props: {
			showCancel: {
				type: Boolean,
				default: true
			},
			cancelText: {
				type: String,
				default: '取消'
			},
			confirmText: {
				type: String,
				default: '确定',
			},
		},
		emits: ['callback'],
		methods: {
			handleCallback(e) {
				this.$emit('callback', e)
			}
		}
	}
</script>

<style lang="scss">
	.success-dialog-cover {
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: 100vh;
		background: rgba(0, 0, 0, 0.3);

		.success-dialog {
			background: #fff;
			position: absolute;
			transform: translate(-50%, -50%);
			left: 50%;
			top: 50%;
			width: calc(100% - 120rpx);
			height: auto;
			border-radius: 5px;

			.dialog-content {
				width: 100%;
				padding: 30rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
			}

			.dialog-footer {
				width: 100%;
				height: 80rpx;
				border-top: 1px solid #efefef;
				display: flex;
				align-items: center;

				.dialog-btn {
					flex-grow: 1;
					height: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 28rpx;
					max-width: calc(50% - 0.5px);
				}

				.line {
					height: 80%;
					width: 1px;
					background: #efefef;
				}

				.dialog-btn.cancel-btn {
					color: #999;
				}

				.dialog-btn.confirm-btn {
					color: #fe7526;
				}
			}
		}
	}
</style>
